import Vue from 'vue';
import Router from 'vue-router';

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(Router);

/* Layout */
import Layout from '@/views/layout/Layout';

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/

export const constantRouterMap = [//无需权限控制的。
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path*',
      component: () => import('@/views/redirect/index')
    }]
  },

  //未用层包裹
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },

  {
    path: '/register',
    component: () => import('@/views/login/register'),
    hidden: true,
  },
  
  {
    path: '/vip',
    component: () => import('@/views/login/vip'),
    hidden: true,
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    name: '错误页面',
    hidden: true
  },

  {//我的桌面
    path: '',
    component: Layout,
    redirect: 'mydesktop',
    name: '首页',
    meta: {
      title: '我的桌面',
      icon: 'dashboard',
    },
    leaf: true,
    children: [
      {
        path: '/mydesktop',
        component: () => import('@/views/mydesktop/index'),
        name: '我的桌面',
        meta: {
          title: '我的桌面',
          icon: 'dashboard',
          noCache: true
        },
      },
    ]
  },
  {
    path: '',
    component: Layout,
    name: '用户管理',
    iconCls:'el-icon-setting',
    meta: {
      title: '用户管理',
      icon: 'dashbord',
    },
    children: [
      {
        path: '/teacher/list',
        component: () => import('@/views/teacher/data'),
        name: '用户列表',
        meta: {
          title: '用户列表',
          icon: 'dashboard',
          noCache: true,
        },
      },
    ]
  },
  {
    path: '',
    component: Layout,
    name: '商品管理',
    iconCls:'el-icon-setting',
    meta: {
      title: '商品管理',
      icon: 'dashbord',
    },
    children: [
      {
        path: '/product/list',
        component: () => import('@/views/product/data'),
        name: '商品列表',
        meta: {
          title: '商品列表',
          icon: 'dashboard',
          noCache: true,
        },
      },
    ]
  },
  /* {
    path: '',
    component: Layout,
    name: '学生管理',
    iconCls:'el-icon-setting',
    meta: {
      title: '学生管理',
      icon: 'dashbord',
    },
    children: [
      {
        path: '/student/list',
        component: () => import('@/views/student/data'),
        name: '学生列表',
        meta: {
          title: '学生列表',
          icon: 'dashboard',
          noCache: true,
        },
      },
    ]
  }, */
  /* {
    path: '',
    component: Layout,
    name: '图书管理',
    iconCls:'el-icon-setting',
    meta: {
      title: '图书管理',
      icon: 'dashbord',
    },
    children: [
      {
        path: '/book/list',
        component: () => import('@/views/book/data'),
        name: '图书列表',
        meta: {
          title: '图书列表',
          icon: 'dashboard',
          noCache: true,
        },
      },
    ]
  }, */
  /*{
    path: '',
    component: Layout,
    name: '课程管理',
    iconCls:'el-icon-setting',
    meta: {
      title: '课程管理',
      icon: 'dashbord',
    },
    children: [
      {
        path: '/course/list',
        component: () => import('@/views/course/data'),
        name: '课程列表',
        meta: {
          title: '课程列表',
          icon: 'dashboard',
          noCache: true,
        },
      },
    ]
  },
  {
    path: '',
    component: Layout,
    name: 'vip管理',
    iconCls:'el-icon-setting',
    meta: {
      title: 'vip管理',
      icon: 'dashbord',
    },
    children: [
      {
        path: '/xhReservation/list',
        component: () => import('@/views/xhReservation/data'),
        name: '预约列表',
        meta: {
          title: '预约列表',
          icon: 'dashboard',
          noCache: true,
        },
      },
    ]
  },
  {
    path: '',
    component: Layout,
    name: '活动管理',
    iconCls:'el-icon-setting',
    meta: {
      title: '活动管理',
      icon: 'dashbord',
    },
    children: [
      {
        path: '/xhEvent/list',
        component: () => import('@/views/xhEvent/data'),
        name: '活动列表',
        meta: {
          title: '活动列表',
          icon: 'dashboard',
          noCache: true,
        },
      },
    ]
  }, */
];

export default new Router({
  mode: 'hash', //后端支持可开  history
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRouterMap, //   createMyRouter(): constantRouterMap
});


/* export const asyncRouterMap = [
  {//我的桌面,无权限，每个账号都可用
    path: '',
    component: Layout,
    redirect: 'mydesktop',
    name: '首页',
    meta: {
      title: '我的桌面',
      icon: 'dashboard',
    },
    leaf: true,
    children: [
      {
        path: '/mydesktop',
        component: () => import('@/views/mydesktop/index'),
        name: '我的桌面',
        meta: {
          title: '我的桌面',
          icon: 'dashboard',
          noCache: true
        },
      },
    ]
  }, 
]*/
